package com.zrf.springCloudTest.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.context.annotation.ScopedProxyMode;
import org.springframework.core.env.Environment;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 测试是否能正常从config-server获取数据
 *
 * @author zhouruifeng
 *         Created by zhouruifeng on 2017/5/4.
 */
@RestController
@RefreshScope()
public class TestController {
    /**
     * 通过vlue获取值
     */
    @Value("${from}")
    private String from;
    @Autowired
    Environment env;

    /**
     * 直接通过@value获取值
     *
     * @return
     */
    @RequestMapping("from")
    public String from() {
        return this.from;
    }

    /**
     * 直接通过key获取远程key的value
     * @param key
     * @return
     */
    @RequestMapping("get/{key}")
    public String get(@PathVariable("key") String key){
        return env.getProperty(key);
    }
}
